package com.example.administrator.printoutindemo;

import android.content.Context;


import com.example.administrator.printoutindemo.database.SQLiteDBService;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


public class FmMaterialDetailInfo implements Serializable {

	private String use_projectname;
	private String projectname;
	private String material;
	private String nums;
	private String unit;
	private int out_storage_detail_id;
	private String jd;
	private String wd;
	private String fmmid;

	private SQLiteDBService sqliteDBservice;

	public FmMaterialDetailInfo() {

	}

	public FmMaterialDetailInfo(Context context) {
		sqliteDBservice = new SQLiteDBService(context);
	}

	// 转化为json对象
	public String ConvertToJson(FmMaterialDetailInfo model) {
		String jsonStr = "";
		JSONObject modelJsonObject = new JSONObject();
		try {
			modelJsonObject.put("out_storage_detail_Id",model.getOut_storage_detail_id());
			modelJsonObject.put("material", model.getMaterial());
			modelJsonObject.put("projectname", model.getProjectname());
			modelJsonObject.put("unit", model.getUnit());
			modelJsonObject.put("jd", model.getJd());
			modelJsonObject.put("wd", model.getWd());
			modelJsonObject.put("fmmid", model.getFmmid());
			modelJsonObject.put("nums", model.getNums());
			modelJsonObject.put("use_projectname", model.getUse_projectname());
			jsonStr = modelJsonObject.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonStr;
	}

	// 将JSON对象转化为list
	public List<FmMaterialDetailInfo> getListFromJSON(String JsonStr) {
		List<FmMaterialDetailInfo> clist = new ArrayList<FmMaterialDetailInfo>();

		try {

			JSONArray jay = new JSONArray(JsonStr);// 将字符串转化为JSON数组

			for (int i = 0; i < jay.length(); i++) {
				JSONObject temp = (JSONObject) jay.get(i);

				FmMaterialDetailInfo n = new FmMaterialDetailInfo();

				n.setUse_projectname(temp.getString("use_projectname"));
				n.setMaterial(temp.getString("material"));
				n.setOut_storage_detail_id(Integer.parseInt(temp
						.getString("out_storage_detail_id")));
				n.setProjectname(temp.getString("projectname"));
				n.setJd(temp.getString("jd"));
				n.setWd(temp.getString("wd"));
				n.setNums(temp.getString("nums"));
				n.setUnit(temp.getString("unit"));
				n.setFmmid(temp.getString("fmmid"));

				clist.add(n);

			}

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

		return clist;

	}

	public String getUse_projectname() {
		return use_projectname;
	}

	public void setUse_projectname(String use_projectname) {
		this.use_projectname = use_projectname;
	}

	public String getProjectname() {
		return projectname;
	}

	public void setProjectname(String projectname) {
		this.projectname = projectname;
	}

	public String getMaterial() {
		return material;
	}

	public void setMaterial(String material) {
		this.material = material;
	}

	public String getNums() {
		return nums;
	}

	public void setNums(String nums) {
		this.nums = nums;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

	public int getOut_storage_detail_id() {
		return out_storage_detail_id;
	}

	public void setOut_storage_detail_id(int out_storage_detail_id) {
		this.out_storage_detail_id = out_storage_detail_id;
	}

	public String getJd() {
		return jd;
	}

	public void setJd(String jd) {
		this.jd = jd;
	}

	public String getWd() {
		return wd;
	}

	public void setWd(String wd) {
		this.wd = wd;
	}

	public String getFmmid() {
		return fmmid;
	}

	public void setFmmid(String fmmid) {
		this.fmmid = fmmid;
	}

}